const { app, ipcMain, dialog, BrowserWindow } = require('electron')
var download = require('./download');

ipcMain.on('get-app-path', (event) => {
  event.sender.send('got-app-path', app.getAppPath())
})

ipcMain.on('downloadall', (event, arg) => {
  const window = BrowserWindow.fromWebContents(event.sender);
  dialog.showOpenDialog(window, {
    properties: ['openDirectory','createDirectory']
  }, (path) => {
    if (path) {
      download.downloadall(arg.baseurl, arg.files, path[0], (err, count) => {
        if (err) {
          event.sender.send('main-process-messages', err);
        }
      },(msg)=>{
        event.sender.send('main-process-messages', msg);
      })
    }
  })
})